<?php
class EditCausa extends Controller
{
	function EditCausa()
	{
		parent::Controller();
		$this->load->library('form_validation');
		$this->load->model('causas_model');
	}
	
	function index()
	{
		$this->load->view('mod_causas/indexEditCausa');
	}
	
	function validSearch()
    {
        $config = array(
               array(
                     'field'   => 'idCausaDelete',
                     'label'   => 'Rol',
                     'rules'   => 'required'
                  ));
	    $this->form_validation->set_rules($config);

        
        if($this->form_validation->run() == FALSE)
        {
             echo validation_errors('<div class="msj_error" align="center">','</div>');
        }
        else
        {
        	$this->showEditCausa();
        } 
    }
	
	function showEditCausa()
	{
		$idCausa = $this->input->post('idCausaDelete');
		//$idCausa = $this->uri->segment(4);
		$data['totalResults'] = $this->causas_model->totalResults($idCausa);
		
		if($data['totalResults'] == 0)
		{
			echo "<div align ='center' class='msj_error'>No existen coincidencias para <b>".$idCausa."</b></div>";
						
		}
		else
		{
			$allCausa = $this->causas_model->getCausaRol($idCausa);
			if(empty($allCausa))
			{
				echo "<div align ='center' class='msj_error'>No existen coincidencias para <b>".$idCausa."</b></div>";
				
			}
			else
			{
				foreach ($allCausa->result() as $row)
		        {
				    $data['rol'] = $row->rol;
					$data['reclamante'] = 	$row->reclamante;
					$data['domicilio_reclamante'] = 		$row->domicilio_reclamante;
					$data['patrocinante'] = 		$row->patrocinante;
					$data['domicilio_patrocinante'] = 		$row->domicilio_patrocinante;
					$data['apoderado'] = 		$row->apoderado;
					$data['domicilio_apoderado'] = 		$row->domicilio_apoderado;
					$data['reclamado'] = 		$row->reclamado;
					$data['domicilio_reclamado'] = 		$row->domicilio_reclamado;
					$data['patrocinante_r'] = 		$row->patrocinante_r;
					$data['domicilio_patrocinante_r'] = 		$row->domicilio_patrocinante_r;
					$data['apoderado_r'] = 		$row->apoderado_r;
					$data['domicilio_apoderado_r'] = 		$row->domicilio_apoderado_r;
					$data['materia'] = 		$row->materia;
					$data['fecha_iniciacion'] = $row->fecha_iniciacion;
					$data['tipo'] = $row->tipo;
					$data['historica'] = $row->historica;
					$data['presidente'] = $row->presidente;
					$data['relator'] = $row->relator;
					$data['procedencia'] = $row->procedencia;
			  		$data['fs_sentencia'] = $row->fs_sentencia;	
			  		$data['apelacion']	=$row->apelacion;
			  		$data['num_fojas']	=$row->num_fojas;	
			  		$data['fecha_remision']	=$row->fecha_remision;	
			  		$data['cumplase']	=$row->cumplase;	
			  		$data['archivada']	=$row->archivada;	 
				}
			$this->load->view('mod_causas/editCausa',$data);
			}
		}
	}
	
	function putEditCausa()
	{	
		$idCausa = $this->input->post('idCausaEdit');
		$hist = 0;
		if($this->input->post('historica') == 'on')
			$hist = 'si';
		$data =array(
				'rol'	=>	$this->input->post('idCausaEdit'),
				'reclamante'	=>	$this->input->post('reclamante'),
				'domicilio_reclamante'	=>	$this->input->post('doreclamante'),
				'patrocinante'	=>	$this->input->post('patrocinante'),
				'domicilio_patrocinante'	=>	$this->input->post('dopatrocinante'),
				'apoderado'	=>	$this->input->post('apoderado'),
				'domicilio_apoderado'	=>	$this->input->post('doapoderado'),
				'reclamado'	=>	$this->input->post('reclamado'),
				'domicilio_reclamado'	=>	$this->input->post('doreclamado'),
				'patrocinante_r'	=>	$this->input->post('patrocinanteR'),
				'domicilio_patrocinante_r'	=>	$this->input->post('dopatrocinanteR'),
				'apoderado_r'	=>	$this->input->post('apoderadoR'),
				'domicilio_apoderado_r'	=>	$this->input->post('doapoderadoR'),
				'materia'	=>	$this->input->post('materia'),
				'fecha_iniciacion'	=>	$this->input->post('fechaEdit'),
				'tipo'	=>	$this->input->post('tipoCausa'),
				'historica'	=>	$hist,
				'presidente' => $this->input->post('presidente'),
				'relator' => $this->input->post('relator'),
				'procedencia'	=>$this->input->post('procedencia'),
			  	'fs_sentencia'	=>$this->input->post('fs_sentencia'),	
			  	'apelacion'	=>$this->input->post('apelacion'),
			  	'num_fojas'	=>$this->input->post('numero_fojas'),	
			  	'fecha_remision'	=>$this->input->post('fecha_remision'),	
			  	'cumplase'	=>$this->input->post('cumplase'),	
			  	'archivada'	=>$this->input->post('archivada')
			);
			if($this->causas_model->updateCausa($data,$idCausa))
			{

				$data['successMensaje'] ="<div class='msj_success' align='center'>Causa Editada Exitosamente<br />";
				$data['successMensaje'] .= "<a href='".base_url()."index.php/mod_causas/causas/makePdf/".$idCausa."'>";
				$data['successMensaje'] .= "<img style='cursor:pointer' src='".base_url()."system/application/views/images/icons/stencil_pdf_icon.gif' title='Generar un PDF con la Causa' alt='pdf'/></a>";
				$data['successMensaje'] .= "&nbsp;&nbsp;<a href='".base_url()."index.php/mod_causas/causas/makePdf/".$idCausa."'>Generar un PDF </a>con la carátula de la causa</div>";

        		echo $data['successMensaje'];
			}
			else
			{
				$data['successMensaje']="<div class='msj_error' align='center'>Error Al editar la causa vuelva a intentarlo.</div>";
        		echo $data['successMensaje'];
			}
	}
	function get_rol()
	{
		$rolid = $this->input->post('idCausaEdit');	

		$rol = $this->causas_model->getRolLike_all(1000,$rolid);
		$materia = $this->causas_model->getMateriaLike_all(1000,$rolid);
		
		echo "<ul>";
		if($rol->num_rows() != 0){
			foreach ($rol->result() as $row)
			{
					echo "<li>".$row->rol."</li>";
				
			}
		}
		else{
			foreach ($materia->result() as $row)
			{
				echo "<li>".character_limiter($row->materia,13)."</li>";
			}
		}
		echo "</ul>";	
	}
	function get_rol_inicio()
	{
		$rolid = $this->input->post('idCausa_libro_reg_inicio');	

		$rol = $this->causas_model->getRolLike_all(1000,$rolid);
		$materia = $this->causas_model->getMateriaLike_all(1000,$rolid);
		
		echo "<ul>";
		if($rol->num_rows() != 0){
			foreach ($rol->result() as $row)
			{
					echo "<li>".$row->rol."</li>";
				
			}
		}
		else{
			foreach ($materia->result() as $row)
			{
				echo "<li>".character_limiter($row->materia,13)."</li>";
			}
		}
		echo "</ul>";	
	}
	function get_rol_final()
	{
		$rolid = $this->input->post('idCausa_libro_reg_final');	

		$rol = $this->causas_model->getRolLike_all(1000,$rolid);
		$materia = $this->causas_model->getMateriaLike_all(1000,$rolid);
		
		echo "<ul>";
		if($rol->num_rows() != 0){
			foreach ($rol->result() as $row)
			{
					echo "<li>".$row->rol."</li>";
				
			}
		}
		else{
			foreach ($materia->result() as $row)
			{
				echo "<li>".character_limiter($row->materia,13)."</li>";
			}
		}
		echo "</ul>";	
	}
}
?>